<template>
    <div class="photo-box">
        <!-- 移动导航栏区域 -->
        <div id="slider" class="mui-slider"><!--mui的坑1因为会占满全屏幕需要去除mui-fullscreen-->
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a :class="['mui-control-item', item.id == 0 ? 'mui-active' : '']" v-for="item in cates" :key="item.id" @click="getPhotoListByCateId(item.id)">
							{{ item.title }}
						</a>
					</div>
				</div>
		</div>

        <!-- 图片列表懒加载区域 -->
           <ul class="photo-list">
                <router-link v-for="item in list" :key="item.id" tag="li" :to="'/home/photoinfo/'+ item.id ">
                    <img v-lazy="item.img_url">

                    <!-- 文字 -->
                    <div class="info">
                        <h1 class="info-title" v-text="item.title"></h1>
                        <div class="info-body"> {{item.zhaiyao}} </div>
                    </div>
                </router-link>
            </ul>
    </div>
</template>
<script>
// 引入导航栏滑动js文件
import mui from '../../lib/mui/js/mui.min.js'
export default {
     data(){
         return {
             cates: [],
            //  图片列表数组
             list: [],
         }
     },
     created(){
         this.getAllCategory();
        //  页面加载请求所有图片数据
        this.getPhotoListByCateId(0);
     },
     mounted(){
        // 初始化滑动控件  放在这里解决不会不滑动问题
        mui('.mui-scroll-wrapper').scroll({
        deceleration: 0.0005 
        })
     },
     methods:{
         getAllCategory(){
            // 获取图片的分类
            this.$http.get('api/getimgcategory').then(result => {
                console.log(result);
                if(result.body.status === 0){
                    // 在获取的的数据是数组在数组第一项添加一个对象
                    result.body.message.unshift({ title: '全部', id: 0})
                    this.cates = result.body.message;
                }
                
            })
         },
         getPhotoListByCateId(id){
             this.$http.get("api/getimages/"+ id).then(result => {
                 if(result.body.status === 0){
                     this.list = result.body.message;
                 }
             })
         }
     }
    
}
</script>
<style lang="scss" scoped>
// 提高滑动流畅度 去除警告
     * {
         touch-action: pan-y;
     }
     .photo-box {
         .mui-scroll {
             .mui-active {
                 color: red;
                 border: none;
             }
         }
     }
     .photo-list {
         list-style: none;
         margin: 0;
         padding: 10px;
         padding-bottom: 0px;
         li {
             width: 100%;
             background-color: #ccc;
             text-align: center;
             margin-bottom: 10px;
             box-shadow: 0 0 9px #999; 
             position: relative;
             .info {
                 position: absolute;
                 bottom: 0;
                 background-color: rgba(0, 0, 0, 0.6);
                 color: #fff;
                 max-height: 84px;
                 overflow: hidden;
                 h1 {
                     text-align: left;
                     font-size: 16px;
                 }
                 .info-body {
                     font-size: 14px;
                 }
             }
             img {
                 width: 100%;
                //  display: block;
                vertical-align: middle;
             }
           img[lazy=loading] {
               
                width: 40px;
                height: 300px;
                margin: auto;
            }

         }
     }
     
</style>
